from user.models import User


class UserLoginMiddleware:
    def __init__(self, get_response):
        self.get_response = get_response

    def __call__(self, request):
        # try:
        #     if request.session['user']:
        #         request.user = User.objects.get(pk = request.session['user'])
        # except Exception as e:
        #     request.user = None
        #     request.session.flush()

        res = self.get_response(request)

        return res


def user_obj(request):
    if request.user:
        return {'user': request.user}
    return {}
